package cn.itcast.n4_共享模型_管程;

import lombok.extern.slf4j.Slf4j;

import static cn.itcast.util.Sleeper.sleep;

/**
 * @program: juc
 * @description:
 * @author: flyduck
 * @create: 2024-09-27 16:26
 **/
@Slf4j(topic = "c.Test22_wait和notify方法_演示带参数的wait方法")
public class Test22_wait和notify方法_演示带参数的wait方法 {

    final static Object lock = new Object();

    public static void main(String[] args) {

        new Thread(() -> {
            synchronized (lock) {
                log.debug("执行....");
                try {
                    lock.wait(5000); //5秒内没人唤醒，自动结束等待
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("其它代码....");
            }
        },"t1").start();

        sleep(1);//1秒后主线程唤醒了它
        log.debug("唤醒 obj 上其它线程");
        synchronized (lock) {
            lock.notify();
        }
    }
}
